// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   NodeSystemDTO.java

package com.hfstu.ifs.dto;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hfstu.framework.util.StringUtil;
import com.hfstu.ifs.model.NodeSystem;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import org.apache.commons.beanutils.BeanUtils;

// Referenced classes of package com.hfstu.ifs.dto:
//			MenuDTO

public class NodeSystemDTO
	implements Serializable
{

	private String id;
	private Integer status;
	private Date createTime;
	private Date lastChangeTime;
	private String appId;
	private String code;
	private String name;
	private String systemImg;
	private String navImg;
	private String backgroundColor;
	private int titleOffset;
	private String description;
	private String menuLayout;
	private String welcomeUrl;
	private String nodeType;
	private Map allNodesMap;
	private List childrens;

	public NodeSystemDTO()
	{
		status = Integer.valueOf(0);
		systemImg = "";
		navImg = "";
		backgroundColor = "";
		nodeType = "nodeSystem";
		allNodesMap = Maps.newHashMap();
		childrens = Lists.newArrayList();
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public Integer getStatus()
	{
		return status;
	}

	public void setStatus(Integer status)
	{
		this.status = status;
	}

	public Date getCreateTime()
	{
		return createTime;
	}

	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}

	public Date getLastChangeTime()
	{
		return lastChangeTime;
	}

	public void setLastChangeTime(Date lastChangeTime)
	{
		this.lastChangeTime = lastChangeTime;
	}

	public String getAppId()
	{
		return appId;
	}

	public void setAppId(String appId)
	{
		this.appId = appId;
	}

	public String getCode()
	{
		return code;
	}

	public void setCode(String code)
	{
		this.code = code;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getSystemImg()
	{
		return systemImg;
	}

	public void setSystemImg(String systemImg)
	{
		this.systemImg = systemImg;
	}

	public String getNavImg()
	{
		return navImg;
	}

	public void setNavImg(String navImg)
	{
		this.navImg = navImg;
	}

	public String getBackgroundColor()
	{
		return backgroundColor;
	}

	public void setBackgroundColor(String backgroundColor)
	{
		this.backgroundColor = backgroundColor;
	}

	public int getTitleOffset()
	{
		return titleOffset;
	}

	public void setTitleOffset(int titleOffset)
	{
		this.titleOffset = titleOffset;
	}

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public String getMenuLayout()
	{
		return menuLayout;
	}

	public void setMenuLayout(String menuLayout)
	{
		this.menuLayout = menuLayout;
	}

	public String getWelcomeUrl()
	{
		return welcomeUrl;
	}

	public void setWelcomeUrl(String welcomeUrl)
	{
		this.welcomeUrl = welcomeUrl;
	}

	public String getNodeType()
	{
		return nodeType;
	}

	public void setNodeType(String nodeType)
	{
		this.nodeType = nodeType;
	}

	public NodeSystemDTO transfer(NodeSystem nodeSystem)
	{
		try
		{
			BeanUtils.copyProperties(this, nodeSystem);
		}
		catch (IllegalAccessException e)
		{
			e.printStackTrace();
		}
		catch (InvocationTargetException e)
		{
			e.printStackTrace();
		}
		return this;
	}

	public void reloadTree(List nodes)
	{
		synchronized (this)
		{
			MenuDTO menuDTO;
			for (Iterator iterator = nodes.iterator(); iterator.hasNext(); allNodesMap.put(menuDTO.getId(), menuDTO))
			{
				menuDTO = (MenuDTO)iterator.next();
				menuDTO.setTree(this);
			}

			for (Iterator iterator1 = nodes.iterator(); iterator1.hasNext();)
			{
				MenuDTO menuDTO = (MenuDTO)iterator1.next();
				String parentId = menuDTO.getParentId();
				MenuDTO parent = (MenuDTO)allNodesMap.get(parentId);
				if (parent != null)
				{
					parent.addChild(menuDTO);
					menuDTO.setParent(parent);
				} else
				{
					childrens.add(menuDTO);
				}
			}

		}
	}

	public List getChildrens()
	{
		return childrens;
	}

	public Map getAllNodesMap()
	{
		return allNodesMap;
	}

	public String toJson()
	{
		StringBuilder json = new StringBuilder();
		json.append("{");
		json.append("\"id\":\"").append(getId()).append("\",");
		json.append("\"code\":\"").append(getCode()).append("\",");
		json.append("\"name\":\"").append(StringUtil.clean(getName())).append("\",");
		json.append("\"systemImg\":\"").append(StringUtil.clean(getSystemImg())).append("\",");
		json.append("\"navImg\":\"").append(StringUtil.clean(getNavImg())).append("\",");
		json.append("\"backgroundColor\":\"").append(StringUtil.clean(getBackgroundColor())).append("\",");
		json.append("\"titleOffset\":\"").append(getTitleOffset()).append("\",");
		json.append("\"description\":\"").append(StringUtil.clean(getDescription())).append("\",");
		json.append("\"menuLayout\":\"").append(StringUtil.clean(getMenuLayout())).append("\",");
		json.append("\"welcomeUrl\":\"").append(StringUtil.clean(getWelcomeUrl())).append("\",");
		json.append("\"nodeType\":\"").append(getNodeType()).append("\",");
		json.append("\"childrens\":[");
		MenuDTO menuDTO;
		for (Iterator iterator = childrens.iterator(); iterator.hasNext(); json.append(menuDTO.toJson()).append(","))
			menuDTO = (MenuDTO)iterator.next();

		if (json.charAt(json.length() - 1) == ',')
			json.deleteCharAt(json.length() - 1);
		json.append("]");
		json.append("}");
		return json.toString();
	}
}
